<?php
include("includes/init.inc.php");
require_once("includes/api.files.php");

mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWD) or die(mysql_error());
mysql_select_db(DB_NAME) or die(mysql_error());

// get file ID
$fileId = $_GET["id"];
$fileInfo = get_file_info($fileId);
$fileName = $fileInfo["name"];
$fileDBName = $fileInfo["file"];
$extension = $fileInfo["ext"];
$contentType = $fileInfo["contentType"];

if($contentType != ""){
	// We'll be outputting a PDF
	header('Content-type: '.$contentType);
	// It will be called downloaded.pdf
	header('Content-Disposition: attachment; filename="'.$fileName.'.'.$extension.'"');
	// The PDF source is in original.pdfz
	readfile('files/'.$fileDBName.'.'.$extension);
} 
else {?>
	no content-typ found;	
<?php }?>